package cloud.seri.iot.aliyun.web.rest

import cloud.seri.iot.aliyun.service.ProductManagerService
import cloud.seri.iot.common.api.ProductManager
import cloud.seri.iot.common.model.CreateProductDTO
import cloud.seri.iot.common.model.ListProductByTagsDTO
import cloud.seri.iot.common.model.PageRequestDTO
import cloud.seri.iot.common.model.UpdateProductDTO
import com.aliyuncs.iot.model.v20180120.*
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.*
import javax.validation.Valid

/**
 * ProductManagerResource controller
 */
@RestController
@RequestMapping("/api/products")
class ProductManagerResource(private val productManagerService: ProductManagerService) : ProductManager
{

    private val log = LoggerFactory.getLogger(this.javaClass)
    /**
     * 创建产品标签
     * @param pk String 产品Key，物联网平台为产品颁发的唯一标识。
     * @param tags List<String> 要创建的标签。标签包括TagKey和TagValue，分别对应标签的key和value。
     * @return CreateProductTagsResponse?
     */
    @PostMapping("/tags/{pk}")
    override fun createProductTags(@PathVariable pk: String, @RequestBody tags: List<CreateProductTagsRequest.ProductTag>): CreateProductTagsResponse?
    {
        return productManagerService.createProductTags(pk, tags)
    }

    /**
     *
     * @param pk String
     * @param tags List<String>
     * @return DeleteProductTagsResponse?
     */
    @DeleteMapping("/tags/{pk}")
    override fun deleteProductTags(@PathVariable pk: String, @RequestBody tags: List<String>): DeleteProductTagsResponse?
    {
        return productManagerService.deleteProductTags(pk, tags)
    }

    /**
     *
     * @param tags List<String>
     * @param dto PageRequestDTO
     * @return ListProductByTagsResponse?
     */
    @GetMapping("/tags/list")
    override fun listProductByTags(dto: ListProductByTagsDTO): ListProductByTagsResponse?
    {
        return productManagerService.listProductByTags(dto)
    }

    /**
     *
     * @param pk String
     * @return ListProductTagsResponse?
     */
    @GetMapping("/tags/{pk}")
    override fun listProductTags(@PathVariable pk: String): ListProductTagsResponse?
    {
        return productManagerService.listProductTags(pk)
    }

    /**
     *
     * @param pk String
     * @param tags List<String>
     * @return UpdateProductTagsResponse?
     */
    @PutMapping("/tags/{pk}")
    override fun updateProductTags(@PathVariable pk: String, @RequestBody tags: List<UpdateProductTagsRequest.ProductTag>): UpdateProductTagsResponse?
    {
        return productManagerService.updateProductTags(pk, tags)
    }


    /**
     * POST createProduct
     */
    @PostMapping
    override fun createProduct(@Valid @RequestBody dto: CreateProductDTO): CreateProductResponse?
    {
        return productManagerService.createProduct(dto)
    }

    /**
     * PUT updateProduct
     */
    @PutMapping
    override fun updateProduct(@Valid @RequestBody dto: UpdateProductDTO): UpdateProductResponse?
    {
        return productManagerService.updateProduct(dto)
    }

    /**
     * GET queryProductList
     */
    @GetMapping("/list")
    override fun queryProductList(dto: PageRequestDTO): QueryProductListResponse?
    {
        return productManagerService.queryProductList(dto)
    }

    /**
     * GET queryProduct
     */
    @GetMapping("/{pk}")
    override fun queryProduct(@PathVariable pk: String): QueryProductResponse?
    {
        return productManagerService.queryProduct(pk)
    }

    /**
     * DELETE deleteProduct
     */
    @DeleteMapping("/{pk}")
    override fun deleteProduct(@PathVariable pk: String): DeleteProductResponse?
    {
        return productManagerService.deleteProduct(pk)
    }

}
